<?php

/**
 * RasterImageBackendGDTest
 *
 * @author vbolshov
 */

use km\graphics\RasterImageBackendGD;

use \PHPUnit_Framework_TestCase;

require_once dirname(__FILE__) . '/../../lib/km/graphics/RasterImageBackend.php';
require_once dirname(__FILE__) . '/../../lib/km/graphics/RasterImageBackendGD.php';

define('TEST_IMAGE', dirname(__FILE__) . '/images/aha.jpg');
list($w, $h) = getimagesize(TEST_IMAGE);
define('TEST_IMAGE_W', $w);
define('TEST_IMAGE_H', $h);

class RasterImageBackendGDTest extends PHPUnit_Framework_TestCase {
	function testSizeInformationGetters()
	{
		$ih = $this->createBackend();
		$this->assertEquals(TEST_IMAGE_W, $ih->getWidth());
		$this->assertEquals(TEST_IMAGE_H, $ih->getHeight());
	}
	function testRegionCopy()
	{
		$ih = $this->createBackend();
		
		$ih->region(0, 0, 50, 50);
		$this->assertEquals(50, $ih->getWidth());
		$this->assertEquals(50, $ih->getHeight());
	}
	function testRegionWithResize()
	{
		$ih = $this->createBackend();
		
		$ih->region(0, 0, 50, 50, 25, 25);
		$this->assertEquals(25, $ih->getWidth());
		$this->assertEquals(25, $ih->getHeight());
	}
	private function createBackend()
	{
		$ih = new RasterImageBackendGD();
		$ih->loadFile(TEST_IMAGE);
		return $ih;
	}
}
